/*
 * @lc app=leetcode.cn id=541 lang=cpp
 *
 * [541] 反转字符串 II
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution {
    void rever(string&s, int start, int k)
    {
        if(s.size() - start < k)
        {
            std::reverse(s.begin() + start, s.end());
        }
        else
        {
            std::reverse(s.begin() + start, s.begin() + start + k);
        }
        return;
    }
public:
    string reverseStr(string s, int k) {
        for(int i = 0; i < s.size(); i += 2*k)
        {
            rever(s, i, k);
        }
        return s;
    }
};
// @lc code=end

